package com.uminho.preferences;

import com.uminho.tools.ApplicationContext;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;

/****c* Preferences/PreferencesHandler
 * DESCRIPTION
 * Classe responsável pelas preferencias
 *
 ****
 */

public class PreferencesHandler{

	
	/****f* PreferencesHandler/getRefreshTime
	 * DESCRIPTION
	 * Método executado para saber o tempo entre notificações
	 * INPUTS
	 * Context
	 * RESULT
	 * Tempo entre notificações
	 ****
	 */
	public static int getRefreshTime(Context c){
		SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(c);
		String result=prefs.getString("selected_notification_time_option", "60");
		if(result!=null){
			int res=Integer.parseInt(result);
			return res;
		}
		else{
			prefs.edit().putString("selected_notification_time_option", "60").commit();
			return 60;
		}		
	}
	

	/****f* PreferencesHandler/getRefreshTime
	 * DESCRIPTION
	 * Método executado para saber o tempo entre notificações
	 * RESULT
	 * Tempo entre notificações
	 ****
	 */
	public static int getRefreshTime(){
		Context d = ApplicationContext.c;
		SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(d);
		String result=prefs.getString("selected_notification_time_option", "60");
		if(result!=null){
			int res=Integer.parseInt(result);
			return res;
		}
		else{
			prefs.edit().putString("selected_notification_time_option", "60").commit();
			return 60;
		}		
	}
	public static void initRefreshTime(){
		try{
		Context d = ApplicationContext.c;
		SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(d);
		String result=prefs.getString("selected_notification_time_option", "600");
		if(result=="600"){
			prefs.edit().putString("selected_notification_time_option", "60");
			prefs.edit().commit();
		}
		}catch (Exception e){
			e.printStackTrace();
		}
		Log.d("Preferences ", "edited");
	}
	/****f* PreferencesHandler/isSelected
	 * DESCRIPTION
	 * Método executado para saber se uma chechbox está seleccionada
	 * Nome da chechbox
	 * RESULT
	 * Booleano com resultado
	 ****
	 */
	public static boolean isSelected(String checkBoxKey, Context c){
		boolean result=false;
		SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(c);
		result=prefs.getBoolean(checkBoxKey, false);
		return result;
	}
	public void teste(){
		//SharedPreferences preferences =  getSharedPreferences("com.uminho.egendme_preferences",0);
        //SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
       // Log.d("teste", "pref: "+preferences.getAll().toString());
	}

}
